﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Blog.Model
{
    public class ConditionalParam
    {

    }

    /// <summary>
    /// 分页参数
    /// </summary>
    public class ListParam
    {
        /// <summary>
        /// 第几页
        /// </summary>
        //[DisplayFormat(ConvertEmptyStringToNull = false)]
        public int PageIndex { get; set; }

        /// <summary>
        /// 每页几条
        /// </summary>
        //[DisplayFormat(ConvertEmptyStringToNull = false)]
        public int PageSize { get; set; }

        /// <summary>
        /// 额外条件（如：名称
        /// </summary>
        public string? Search { get; set; } 

        public int Take()
        {
            if (PageSize <= 0)
            {
                throw new ValidationException("pageSize必须是正数！");
            }

            return PageSize;
        }

        public int Skip()
        {
            if (PageIndex <= 0)
            {
                throw new ValidationException("pageIndex必须是正数！");
            }

            return (PageIndex - 1) * PageSize;
        }
    }

    public class ListIds
    {
        public List<string> ids { get; set; }
    }
}
